home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / book / src / doslib.c < prev    next >
C/C++ Source or Header  |  1993-07-08  |  2KB  |  90 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <ctype.h>
  5. #include    <msdos.cf>
  6. #include    <system.cf>
  7. #include    <status.cf>
  8. #include    <egb.h>
  9. #include    "book.h"
  10. #include    "lib.h"
  11. #include    "doslib.h"
  12.  
  13.  
  14. /*
  15.  *  int chdrv(int no)
  16.  *              --- 指定のドライブに移動する
  17.  *
  18.  *  入力 :  移動先ドライブ (A:0, B:1, ...)
  19.  *  出力 :  現在ドライブ   (A:0, B:1, ...)
  20. */
  21. int     chdrv(int no)
  22. {
  23.     Registers.AX.R = 0x0E00;
  24.     Registers.DX.R = no;
  25.     calldos();
  26.     return Registers.AX.LH.L;
  27. }
  28.  
  29.  
  30. /*
  31.  *  int chdir(char *name)
  32.  *              --- 指定のディレクトリに移動する(指定ドライブ内)
  33.  *
  34.  *  入力 :  移動先ディレクトリのパスリスト
  35.  *          ドライブ名が指定された場合は、指定ドライブのカレントディレクトリ
  36.  *          は移動するが、そのドライブに移動するわけではない
  37.  *  出力 :  0     → エラーなし
  38.  *          other → エラーあり
  39. */
  40. int     chdir(char *name)
  41. {
  42.     Registers.AX.R = 0x3B00;
  43.     Registers.DX.R = (int)name;
  44.     Registers.DS.R = getds();
  45.     calldos();
  46.  
  47.     return (Registers.Flags & 1);
  48. }
  49.  
  50.  
  51. /*
  52.  *  int getdir(char *name)
  53.  *              --- 現在のドライブ名からのフルパスリストを取得
  54.  *
  55.  *  入力 :  なし
  56.  *  出力 :  char *name にドライブ名 + ":" + ルートからのフルパスリストが返る
  57.  *          なんらかのエラーにより、カレントディレクトリが取得できなかった
  58.  *          場合は、ドライブ名 + ":" + "\" のみが返される
  59.  *          関数の戻り値は 0 → エラーなし other → エラーあり
  60. */
  61. int     getdir(char *name)
  62. {
  63. int     error = 0;
  64.  
  65.     /* カレントディレクトリを取得 */
  66.     Registers.AX.R = 0x4700;
  67.     Registers.DX.R = 0x0000;
  68.     Registers.SI.R = (int)name+3;
  69.     Registers.DS.R = getds();
  70.     calldos();
  71.     if ((error = (Registers.Flags & 1)) != 0)
  72.         *(name+3) = '\0';
  73.  
  74.     /* カレントドライブを取得 */
  75.     Registers.AX.R = 0x1900;
  76.     calldos();
  77.  
  78.     /*  ドライブ名に変換  */
  79.     *(name++) = 'A' + (Registers.AX.R & 0xFF);
  80.     *(name++) = ':';
  81.     *(name++) = '\\';
  82.  
  83.     /*  パスリストが継続する場合は、最後に \ を付加  */
  84.     if (*name != '\0')
  85.         strcat(name, "\\");
  86.  
  87.     return error;
  88. }
  89.  
  90.